// select滚动到底部触发
const vSelectLoadMore = {
  name: 'select-load-more',
  beforeMount: (el, binding) => {
    const selectDom = document.querySelector('.single-select-loadmore .el-select-dropdown__wrap')
    function loadMores() {
      // 判断是否到底
      const isBase = this.scrollHeight - this.scrollTop <= this.clientHeight
      if (isBase) {
        binding.value && binding.value()
      }
    }
    //将获取到的dom和函数挂载到el-select上，实例销毁时好处理
    el.selectDomInfo = selectDom
    el.selectLoadMore = loadMores
    // 监听滚动事件
    selectDom?.addEventListener('scroll', loadMores.bind(selectDom))
  },
  beforeUnmount(el) {
    if (el.selectLoadMore) {
      el.selectDomInfo.removeEventListener('scroll', el.selectLoadMore)
      delete el.selectDomInfo
      delete el.selectLoadMore
    }
  },
}

export default vSelectLoadMore
